#include<iostream>
#include<unordered_map>
using namespace std;
int main()
{
	unordered_map<string, int> mp;
	int n;cin >> n;
	int ret = 0;
	while (n--)
	{
		string a,b;cin >> a >> b;
		 a = a.substr(0, 2);
		 if (a == b) continue;
		 ret += mp[b + a];
		 mp[a + b]++;
	}
	cout << ret << endl;
	return 0;
}
//#include<iostream>
//#include<unordered_map>
//#include<set>
//using namespace  std;
//const int N = 1e6 + 10;
//int main()
//{
//	unordered_map<string, string> mp;
//	unordered_map<string, int> k;
//	int n;cin >> n;
//	while (n--)
//	{
//		string s1, s2;
//		cin >> s1 >> s2;
//		mp[s1.substr(0, 2)] = s2;
//	}
//	int count = 0;
//	for (auto v : mp)
//	{
//		auto t = v.second;
//		if (mp[t].empty())
//		{
//			mp.erase(t);
//			continue;
//		}
//		if (mp[t] == v.first) {
//			count++;
//			if (k[v.first] > 0 || k[t] > 0) count--;
//			k[t]++;
//			k[v.first]++;
//		}
//	}
//	cout << count << endl;
//	return 0;
//}
////#include<iostream>
////#include<string>
////#include<cstring>
////#include<vector>
////#include<unordered_map>
////#include<unordered_set>
////using namespace std;
////int main()
////{
////	unordered_map<string, string, string>mp;
////	int n;cin >> n;
////	for (int i = 1; i <= n; i++)
////	{
////		string s1, s2;cin >> s1 >> s2;
////		mp[s1] = s2;
////		mp[mp[s1]] = s1.substr(1, 2);
////	}
////	for (auto v : mp)
////	{
////		auto s = v.second;
////		if(v[s] == v[v.first])
////	}
////	return 0;
////}